package xyz.coolcsm.security.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.coolcsm.security.entity.Question;
import xyz.coolcsm.security.entity.SysUser;
import xyz.coolcsm.security.entity.SysUserInfo;
import xyz.coolcsm.security.mapper.QuestionMapper;
import xyz.coolcsm.security.service.QuestionService;
import xyz.coolcsm.security.service.SysUserInfoService;
import xyz.coolcsm.security.service.SysUserService;
/**
 * @author 什锦
 * @since 2021-06-1
 */
@Service
public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> implements QuestionService {

    @Autowired
    SysUserService sysUserService;

    @Autowired
    SysUserInfoService sysUserInfoService;

    @Autowired
    QuestionMapper questionMapper;

    @Override
    public void issueQuestion(String username, Question question) {
        SysUser sysUser = sysUserService.selectByName(username);
        SysUserInfo sysUserInfo = sysUserInfoService.getById(sysUser.getId());
        question.setAuthorId(sysUserInfo.getUid());
        question.setAuthorAvatar(sysUserInfo.getAvatar());
        question.setAuthorName(sysUserInfo.getNickname());
        questionMapper.insert(question);
    }
}
